import { createStore, Store, useStore as userVuexStore } from "vuex"
// 导入login 模块
import login from "./login/index"
import system from "./main/system/index"
// 导入定义的类型
import { IRootState, IStoreType } from "./types"

const store = createStore<IRootState>({
  state() {
    return {
      name: "哈哈哈",
      age: 2131
    }
  },
  mutations: {},
  getters: {},
  actions: {},
  modules: {
    login,
    system
  }
})

// 页面刷新的时候 调用函数
export function setupStore() {
  store.dispatch("login/loadLocalLogin")
}

// 自定义返回store
export function useStore(): Store<IStoreType> {
  return userVuexStore()
}

export default store
